package com.tianda.rbac_demo.interceptor;

import cn.dev33.satoken.stp.StpUtil;
import com.tianda.rbac_demo.exception.BusException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

@Component
public class CheckLoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        //使用sa-token判断是否登录
        if(StpUtil.isLogin()){
            return true;
        }
        //抛出逻辑异常
        throw new BusException(1001,"未登录");

    }
}
